/****** Object:  UserDefinedFunction [dbo].[fn_DecryptList]    Script Date: 06/09/2015 17:05:24 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_DecryptList]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[fn_DecryptList]
GO

/****** Object:  UserDefinedFunction [dbo].[fn_DecryptList]    Script Date: 06/09/2015 17:05:24 ******/
CREATE FUNCTION [dbo].[fn_DecryptList] 
(
	@cipherTextList CryptoUpdater readonly
)
RETURNS @plainTextList TABLE (PlainText VARCHAR(20), CipherText VARCHAR(50))
AS
BEGIN

INSERT @plainTextList(CipherText) 
SELECT CipherText 
FROM @cipherTextList

UPDATE @plainTextList 
SET PlainText = CONVERT(VARCHAR(20), DecryptByPassPhrase([Global].dbo.fn_OpenSesame(), CAST(N'' AS XML).value('xs:base64Binary(sql:column("CipherText"))', 'varbinary(255)')))

RETURN

END
GO